/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.questionnaire;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.questionnaire.Question;
import com.blandware.atleap.model.questionnaire.Questionnaire;
import com.blandware.atleap.persistence.core.DAO;

/**
 * <p>DAO for questions.</p>
 * <p><a href="QuestionDAO.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2006/10/31 11:55:53 $
 */
public interface QuestionDAO extends DAO {

    // ~ CRUD methods ================================================================

    /**
     * Creates a new question in a questionnaire.
     *
     * @param question question to create
     * @param questionnaire questionnaire to which to put question
     * @return created question ID
     */
    public Long createQuestion(Question question, Questionnaire questionnaire);

    /**
     * Retrieves a question by its ID.
     *
     * @param questionId ID of question to retrieve
     * @return retrieved question
     */
    public Question retrieveQuestion(Long questionId);

    /**
     * Updates a question.
     *
     * @param question question to update
     * @param questionnaire questionnaire to which question belongs
     */
    public void updateQuestion(Question question, Questionnaire questionnaire);

    /**
     * Deletes a question.
     *
     * @param question question to delete
     */
    public void deleteQuestion(Question question);

    // ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of questions.
	 *
	 * @param queryInfo Object that contains information about how to filter
     * and sort data
	 * @return Collection of questions
	 */
    public PartialCollection listQuestions(QueryInfo queryInfo);

    /**
     * Changes a question position so that it becomes one position higher or
     * lower.
     *
     * @param question what question to move
     * @param up if true, question is moved up, else down
     */
    public void moveQuestion(Question question, boolean up);

    /**
     * Creates a copy of question placing it to a given questionnaire.
     *
     * @param question question to copy
     * @param questionnaire where to put a question
     * @return new question
     */
    public Question copyQuestion(Question question, Questionnaire questionnaire);

    /**
     * Returns least and most positions of question which owner has given ID.
     *
     * @param ownerId ID of questionnaire which children will be considered
     * @return two-element array: least and most occupied position
     */
    public Integer[] getFirstLastOccupiedPositions(Long ownerId);
}
